package com.zimmur.quartz;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.zimmur.model.order.Order;
import com.zimmur.service.order.IOrderDetailService;
import com.zimmur.service.order.IOrderService;
import com.zimmur.tools.DateUtils;

@Component
public class ProcessOrderDone {
private Logger log = LoggerFactory.getLogger(ProcessOrderDone.class);
	
	@Autowired @Qualifier("orderServiceImpl")
	private IOrderService orderService;
	@Resource
	private IOrderDetailService orderDetailService;
	/**
	 * 每天凌晨0点，处理发货超过7天的订单
	 */
	@Scheduled(cron="0 0 0 * * ?")
	public void orderDone(){
		log.info("orderDone task begin");
		try {
			int dateTime = DateUtils.getNowUnixTime()-(7*60*60*24);
			List<Order> orders = orderService.selectOrderByShipDateOut(dateTime);
			if(orders!=null && orders.size()>0){
				Iterator<Order> iterator=orders.iterator();
				while (iterator.hasNext()) {
					Order order=iterator.next();
					order.setOderStatus("30");
					order.setOrderStatusText("已完成");
					order.setReceiptStatus(1);
					orderService.updateByPrimaryKeySelective(order);
				}
			}
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		log.info("orderDone task end");
	}
}
